 class animal{
        String name;
        int age;
        public animal(String name, int age) {
            this.name = name;
            this.age = age;
        }
        public void eat(){
            System.out.println(name+"正在吃东西");
        }
    }
 class Dog extends animal{
     public Dog(String name, int age) {
         super(name, age);
     }

     @Override//这里对父类的方法进行了重写
     public void eat() {
         System.out.println(name+"吃狗粮");
     }

     public  void bark(){
            System.out.println(name+"汪汪叫");
        }
    }
    class Cat extends animal{

        public Cat(String name, int age) {
            super(name, age);
        }

        @Override
        public void eat() {
            System.out.println(name+"吃猫粮");
        }
        public void CatMouse(){
            System.out.println(name+"在抓老鼠");
        }
    }

public class Test2  {
    public static void eatFood(animal animal){
        animal.eat();
    }
    public static void main(String[] args) {
        Dog dog=new Dog("heihei",13);
        Cat cat =new Cat("mimi",5);
        animal animal=cat;
        animal.eat();//向上转型
        animal=dog;
        cat=(Cat)animal;//这里就是向下转型
        if(animal instanceof Cat){//我们已经把animal转型为dog,这里再把dog
                                  //转型为cat，会报错。
            cat=(Cat)animal;
            cat.CatMouse();
        }

        eatFood(dog);
        eatFood(cat);
   animal animal1=new Dog("hihi",10);
   animal1.eat();//这里就是
   //animal1.bark()//这里报错

    }


}
